{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": [
    "# 模型的不同分类方式\n",
    "角度1：按照模型功能的不同：\n",
    "- 非对话模型（LLMs、Text Model）\n",
    "- 对话模型（Chat Models）（ 推荐 ）\n",
    "- 嵌入模型（Embedding Models）( 暂不考虑 )\n",
    "\n",
    "角度2：模型调用时，几个重要参数的书写位置的不同：\n",
    "- 硬编码：写在代码文件中\n",
    "- 使用环境变量\n",
    "- 使用配置文件（ 推荐 ）\n",
    "\n",
    "角度3：具体调用的API\n",
    "- OpenAI提供的API\n",
    "- 其它大模型自家提供的API\n",
    "- LangChain的统一方式调用API（ 推荐 ）"
   ],
   "id": "79b03e3aaf18f456"
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 角度1：非对话模型的调用",
   "id": "449fca838e46b2f"
  },
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-10-16T15:20:56.053382Z",
     "start_time": "2025-10-16T15:20:51.528211Z"
    }
   },
   "source": [
    "import os\n",
    "\n",
    "import dotenv\n",
    "\n",
    "from langchain_openai import OpenAI\n",
    "\n",
    "dotenv.load_dotenv()\n",
    "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\")\n",
    "os.environ[\"OPENAI_BASE_URL\"] = os.getenv(\"OPENAI_BASE_URL\")\n",
    "\n",
    "llm = OpenAI()\n",
    "str = llm.invoke(\"写一首关于春天的诗\")\n",
    "print(str)"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "春天来了，大地复苏\n",
      "花开满园，绿意融融\n",
      "微风吹拂，暖意袭人\n",
      "春雨滋润，万物生长\n",
      "\n",
      "蝴蝶飞舞，蜜蜂采蜜\n",
      "小鸟欢歌，蝉声嘹亮\n",
      "草儿抽芽，树木吐绿\n",
      "春光明媚，心情舒畅\n",
      "\n",
      "田野耕种，农夫忙碌\n",
      "春日收获，满载而归\n",
      "人们欢庆，春节佳节\n",
      "家家团圆，幸福永远\n",
      "\n",
      "春天的魅力，无穷无尽\n",
      "给人们带来，希望和憧憬\n",
      "让我们珍惜，每一个春天\n",
      "感恩大自然，赐\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 角度1：对话模型的调用",
   "id": "605837070f63bcd5"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-16T15:58:51.140011Z",
     "start_time": "2025-10-16T15:58:48.535964Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "from langchain_core.messages import SystemMessage, HumanMessage\n",
    "import os\n",
    "import dotenv\n",
    "\n",
    "dotenv.load_dotenv()\n",
    "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\")\n",
    "os.environ[\"OPENAI_BASE_URL\"] = os.getenv(\"OPENAI_BASE_URL\")\n",
    "\n",
    "CHAT_MODEL = ChatOpenAI()\n",
    "message = [\n",
    "    SystemMessage(content=\"我是人工智能助手，我叫小智\"),\n",
    "    HumanMessage(content=\"你好，我是小明，很高兴认识你\")\n",
    "]\n",
    "response = CHAT_MODEL.invoke(message)\n",
    "\n",
    "print(type(response))\n",
    "print(response)"
   ],
   "id": "464a72627e5c4774",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'langchain_core.messages.ai.AIMessage'>\n",
      "content='你好，小明！我也很高兴认识你。有什么问题需要我的帮助吗？' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 32, 'prompt_tokens': 45, 'total_tokens': 77, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': 'gpt-3.5-turbo-0125', 'system_fingerprint': 'fp_0165350fbb', 'id': 'chatcmpl-CRKfJmnDDXbGb4CFRflJ9na4FubUM', 'service_tier': None, 'finish_reason': 'stop', 'logprobs': None} id='run--b2f77421-6e78-4ec9-adf0-ec7a2ae84c8f-0' usage_metadata={'input_tokens': 45, 'output_tokens': 32, 'total_tokens': 77, 'input_token_details': {}, 'output_token_details': {}}\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 角度1：嵌入模型的调用",
   "id": "4309bb0a556100c4"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-17T13:49:16.726898Z",
     "start_time": "2025-10-17T13:49:14.398215Z"
    }
   },
   "cell_type": "code",
   "source": [
    "import os\n",
    "import dotenv\n",
    "from langchain_openai import OpenAIEmbeddings\n",
    "\n",
    "dotenv.load_dotenv()\n",
    "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\")\n",
    "os.environ[\"OPENAI_BASE_URL\"] = os.getenv(\"OPENAI_BASE_URL\")\n",
    "\n",
    "embeddings_mode = OpenAIEmbeddings(\n",
    "    model=\"text-embedding-3-small\"\n",
    ")\n",
    "\n",
    "res1 = embeddings_mode.embed_query('我是文档中的数据')\n",
    "print(res1)"
   ],
   "id": "7a5e7b072af7c397",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-0.004141181707382202, 0.025951068848371506, 0.03639602288603783, -0.026253528892993927, 0.039400458335876465, -0.022039253264665604, -0.028632881119847298, 0.04399785026907921, -0.06319397687911987, -0.07166285812854767, -0.01479029469192028, 0.044320475310087204, -0.00018131847900804132, 0.010898642241954803, 0.019922032952308655, 0.05524936318397522, -0.023228928446769714, -0.002815398620441556, -0.009587982669472694, 0.01567751169204712, 0.013227584771811962, 0.03869471698999405, 0.024297621101140976, 0.007803468499332666, 0.021333513781428337, -0.007702648639678955, 0.01423578429967165, -0.008524331264197826, 0.01778464950621128, -0.040630463510751724, -0.02647533267736435, -0.03790832310914993, 0.00814121589064598, 0.01798628829419613, 0.002933862153440714, 0.04307030513882637, 0.02792714163661003, 0.01069700252264738, 0.026676973327994347, -0.07646188884973526, -0.029903214424848557, 0.0008052997873164713, 0.029479769989848137, 0.01701841689646244, 0.02897566929459572, -0.008267240598797798, -0.01871219277381897, 0.03996504843235016, 0.021736793220043182, -0.0004467586404643953, -0.03191961348056793, 0.015526280738413334, 0.06629923731088638, 0.0005100861890241504, 0.046699825674295425, 0.022301385179162025, 0.011080118827521801, 0.03921898081898689, -0.011553972959518433, -0.040791772305965424, 0.04371555522084236, 0.011715284548699856, -0.02804812602698803, 0.030871085822582245, -0.024963032454252243, -0.005293050315231085, -0.03552896901965141, -0.011342250742018223, -0.008161379024386406, -0.05371689796447754, 0.03760586306452751, 0.06440381705760956, -0.049966394901275635, 0.02025473862886429, 0.018571045249700546, -0.021958597004413605, -0.08025272190570831, 0.01894407905638218, -0.022079581394791603, -0.022765157744288445, -0.014074472710490227, 0.064363494515419, 0.018550880253314972, -0.05036967620253563, -0.010112246498465538, -0.02082941308617592, -0.008100887760519981, 0.010071918368339539, 0.005882847122848034, 0.0028557267505675554, -0.03496437892317772, 0.026334185153245926, -0.03756553307175636, -0.021797284483909607, -0.03381503000855446, 0.032443877309560776, -0.03365371748805046, 0.007742976304143667, -0.023188600316643715, -0.03585159406065941, 0.013691356405615807, -0.007143097463995218, 0.02647533267736435, 0.014225702732801437, -0.021313348785042763, 0.03677913919091225, 0.02409598045051098, -0.057306092232465744, -0.0653313621878624, 0.017088990658521652, -0.11146660149097443, 0.015858987346291542, -0.02236187644302845, -0.02205941639840603, 0.01671595685184002, 0.01905498094856739, 0.03093157708644867, -0.03615405410528183, 0.000672973517794162, 0.01035421434789896, -0.0222005657851696, 0.05831428989768028, -0.028713537380099297, -0.035831429064273834, 0.004713335074484348, -0.006649079266935587, 0.015143164433538914, -0.06174217164516449, -0.034177981317043304, -0.020537035539746284, 0.006084487307816744, -0.03484339267015457, 0.018470225855708122, -0.07843796163797379, 0.008373101241886616, -0.014739884994924068, -0.05178115516901016, 0.058031994849443436, 8.77449128893204e-05, -0.042626697570085526, 0.05742707476019859, 0.023652372881770134, 0.022422369569540024, 0.01073733065277338, -0.04238472878932953, -0.036214545369148254, -0.020889904350042343, 0.03591208532452583, -0.003286732127889991, 0.002263409085571766, -0.020113591104745865, -0.010187861509621143, -0.05299099534749985, -0.0203253123909235, 0.017512435093522072, 0.031596988439559937, 0.05843527615070343, -0.024035489186644554, 0.005978626199066639, 0.027685172855854034, -0.0029741900507360697, -0.01897432468831539, -0.01939776912331581, 0.0014719720929861069, 0.0162521842867136, 0.021071381866931915, 0.026293857023119926, -0.023370077833533287, -0.02367253787815571, 0.002258368069306016, -0.015526280738413334, -0.01917596533894539, 0.019004570320248604, -0.019468342885375023, -0.04198145121335983, 0.006820473354309797, 0.0022785321343690157, -0.013247748836874962, 5.1237042498541996e-05, 0.010384460911154747, -0.034823231399059296, 0.0032060761004686356, -0.007380024529993534, 0.014013980515301228, -0.018550880253314972, -0.032826993614435196, 0.027806157246232033, 0.050087377429008484, -0.0448850654065609, 0.02355155348777771, -0.0046427613124251366, 0.05831428989768028, 0.020930232480168343, -0.013983734883368015, 0.02877402864396572, 0.004932618699967861, 0.009356096386909485, -0.027060089632868767, -0.022603845223784447, 0.041779808700084686, 0.009885401464998722, 0.02605189010500908, -0.02405565418303013, -0.0322624035179615, -0.02609221823513508, 0.005257763434201479, 0.003805955173447728, -0.004272247664630413, -0.0611775778234005, -0.04819196090102196, 0.01863153651356697, 0.04629654809832573, 0.003132981713861227, 0.016897432506084442, -0.02117220126092434, 0.033714208751916885, 0.01763341948390007, 0.024761393666267395, 0.0446430966258049, -0.011634628288447857, 0.018853340297937393, -0.010686920955777168, 0.06202446669340134, 0.03663799166679382, -0.007092687301337719, 0.0570237934589386, -0.022261057049036026, -0.03661782667040825, -0.010465116240084171, -0.0285118967294693, 0.0403280034661293, 0.008181543089449406, 0.01098938100039959, 0.006326455157250166, -0.025043688714504242, -0.029943540692329407, -0.03712192550301552, 0.004698212258517742, -0.0003153775760438293, 0.009577900171279907, -0.005696330219507217, 0.003508536145091057, -0.0052426401525735855, 0.010102164931595325, 0.024136308580636978, -0.006850719451904297, 0.008947775699198246, -0.023793520405888557, -0.0263543501496315, 0.05553165823221207, 0.047546714544296265, 0.03508536145091057, 0.024378277361392975, 0.006805350538343191, -0.03645651414990425, -0.013409060426056385, -0.01069700252264738, 0.04621589183807373, 0.051579516381025314, 0.05355558544397354, -0.0017441860400140285, -0.0243984404951334, -0.016655465587973595, 0.008151297457516193, -0.017512435093522072, 0.010636510327458382, 0.006896088365465403, 0.01614128239452839, -0.0014833143213763833, -0.0325850248336792, -0.025527626276016235, 0.041013579815626144, 0.039400458335876465, -0.011614464223384857, -0.02881435677409172, -0.027806157246232033, 0.0033043755684047937, -0.013862750492990017, 0.04718376323580742, 0.016221938654780388, -0.03716225549578667, 0.0018424856243655086, 0.002534362953156233, 0.027604516595602036, -0.0019117993069812655, 0.018641619011759758, -0.02970157377421856, -0.00370261468924582, 0.007304409518837929, -0.022966796532273293, -0.008211789652705193, -0.03403683379292488, -0.01041470654308796, -0.052507057785987854, 0.01332840509712696, 0.0024095980916172266, 0.03347223997116089, -0.037283238023519516, -0.031092889606952667, -0.005373706109821796, -0.004403313621878624, 0.020295066758990288, -0.007707689423114061, 0.03373437374830246, 0.03081059455871582, -0.025809921324253082, 0.024539589881896973, -0.05093426629900932, -0.045893266797065735, -0.004879688378423452, -0.015818659216165543, -0.03369404748082161, 0.040469150990247726, 3.729552554432303e-05, -0.0448850654065609, -0.01442734245210886, 0.021152036264538765, 0.021877940744161606, 0.0080857640132308, 0.011453152634203434, -0.017764484509825706, -0.022503025829792023, 0.00128923577722162, -0.022563517093658447, -0.007758099585771561, 0.01275373063981533, -0.020930232480168343, 0.06771071255207062, 0.0018613893771544099, -0.06073397025465965, 0.04018685594201088, 0.005756822414696217, 0.006598669569939375, -0.005202312488108873, 0.07533270865678787, -0.05738674849271774, -0.019458260387182236, 0.04319129139184952, -0.01737128756940365, -0.04290899261832237, 0.0014518080279231071, -0.010061836801469326, -0.0058878883719444275, 0.0044083548709750175, -0.0045721870847046375, -0.045127034187316895, 0.025305820629000664, 0.03262535482645035, -0.02367253787815571, -0.005751781165599823, -0.027685172855854034, 0.017038580030202866, -0.009961016476154327, 0.06004839390516281, 0.00010578223736956716, -0.0027775911148637533, 0.012461353093385696, -0.02343056909739971, 0.049885738641023636, -0.027342384681105614, -0.03631536662578583, -0.002686853054910898, -0.001245127059519291, -0.00893265288323164, 0.00631133234128356, -0.0013207420706748962, -0.017391450703144073, -0.018833177164196968, 0.08142223954200745, 0.0025557870976626873, -0.025608280673623085, -0.013499798253178596, -0.018873505294322968, 0.005605592392385006, -0.019538916647434235, -0.011453152634203434, -0.021414170041680336, 0.009981180541217327, -0.009708966128528118, 0.029378948733210564, -0.03637585788965225, 0.0005957832327112556, 0.04702245071530342, -0.015133082866668701, 0.030951742082834244, 0.025043688714504242, -0.02316843718290329, 0.05738674849271774, 0.03389568626880646, 0.017683828249573708, 0.0263543501496315, 0.05432181805372238, 0.016887350007891655, -0.0038714881520718336, -0.022099744528532028, -0.018833177164196968, -0.022603845223784447, -0.00369757367298007, -0.024257292971014977, -0.06573463976383209, 0.0122395483776927, 0.02147466130554676, -0.0024322825483977795, -0.015536363236606121, 0.00027284413226880133, 0.010535690933465958, -0.005298091098666191, 0.045086707919836044, 0.0016421058680862188, -0.04379621148109436, -0.005696330219507217, -0.012249630875885487, 0.04536900296807289, 0.023491060361266136, 0.01069700252264738, -0.04153784364461899, -0.08493077009916306, 0.044199489057064056, -0.02550746127963066, -0.0007926973048597574, -0.01041470654308796, 0.03500470519065857, -0.02258368209004402, 0.004370547365397215, -0.02393466979265213, 0.041094232350587845, 0.06178249791264534, -0.0005422225804068148, 0.045086707919836044, -0.06775104254484177, -0.003949623554944992, -0.01628243178129196, 0.008599946275353432, -0.05053098499774933, -0.05137787386775017, -0.01813751831650734, -0.018923915922641754, -0.024600081145763397, 0.03718241676688194, -0.003962226212024689, -0.015727920457720757, -0.022603845223784447, -0.03204059600830078, 0.013741767033934593, -0.03421831130981445, -0.0055400594137609005, 0.03631536662578583, 0.013217502273619175, 0.016726039350032806, -0.03123403713107109, 0.051660168915987015, -0.06722678244113922, -0.011372496373951435, -0.022220728918910027, -0.02601156197488308, -0.024378277361392975, 0.008625151589512825, 0.020950397476553917, -0.023349912837147713, -0.02881435677409172, -0.020547116175293922, 0.034056998789310455, -0.05545100197196007, 0.012995698489248753, 0.0005009493906982243, -0.043352603912353516, -0.0051040127873420715, 0.0027851527556777, 0.007440516259521246, -0.00446632644161582, 0.017260385677218437, 0.03806963562965393, -0.0019937155302613974, 0.0046175564639270306, -0.04294932261109352, -0.010344132781028748, -0.020315231755375862, -0.003579110139980912, -0.03879553824663162, -0.026293857023119926, 0.02843124233186245, -0.004236960783600807, -0.03954160585999489, -0.01239077840000391, 0.011130528524518013, 0.14848770201206207, -0.033411748707294464, -0.011059954762458801, 0.07009007036685944, 0.014699556864798069, -0.012652910314500332, 0.016685711219906807, 0.03421831130981445, -0.005116615444421768, -0.0203656405210495, -0.012723485007882118, -0.030024196952581406, -0.05468476936221123, -0.009547654539346695, -0.016857104375958443, 0.022099744528532028, -0.01487095095217228, -0.011261594481766224, -0.01332840509712696, 0.03661782667040825, -0.01423578429967165, -0.054039523005485535, -0.006966662593185902, 0.043513912707567215, 0.015617018565535545, 0.04706277698278427, 0.028209436684846878, -0.001402658293955028, 0.019236456602811813, -0.00020620842406060547, 0.01035421434789896, 0.005998790264129639, 0.014064391143620014, -0.03131469339132309, 0.015123000368475914, 0.005691289436072111, -0.020930232480168343, -0.02728189341723919, -0.036517005413770676, -0.03819061815738678, 0.005222476087510586, 0.017391450703144073, -0.0096434336155653, 0.024116145446896553, 0.01319733913987875, 0.04403817653656006, -0.01073733065277338, 0.019760720431804657, -0.0047309789806604385, 0.020002689212560654, -0.0022671897895634174, -0.00407060794532299, 0.024983197450637817, 0.02470090053975582, -0.03097190521657467, 0.007652238477021456, 0.023712866008281708, -0.021958597004413605, 0.02181744948029518, 0.0017265425994992256, 0.011160774156451225, -0.04085226729512215, 0.007208630442619324, 0.0202849842607975, 0.03696061298251152, 0.021575480699539185, -0.028027961030602455, 0.030246000736951828, -0.027765829116106033, -0.01004671398550272, -0.019266702234745026, 0.015203656628727913, -0.005943339318037033, -0.004236960783600807, 0.009159497916698456, 0.00039067750913091004, 0.0047990321181714535, 0.006744858343154192, 0.01694784313440323, -0.03389568626880646, 0.0014152608346194029, -0.007541336584836245, -0.054725099354982376, 0.005212394054979086, -0.023390240967273712, -0.02919747307896614, 0.06162118911743164, -0.016030380502343178, 0.051740825176239014, -0.03762602433562279, -0.024297621101140976, 0.025688936933875084, -0.0122597124427557, -0.012904960662126541, -0.0061399382539093494, -0.0026566071901470423, -0.014134964905679226, -0.01644374243915081, -0.0021978761069476604, -0.037827666848897934, -0.00026150187477469444, 0.049079179763793945, -0.010455034673213959, -0.008176502771675587, -0.005671125371009111, 0.023269256576895714, 0.015516199171543121, -0.008599946275353432, -0.03643634915351868, 0.003158186562359333, -0.020063180476427078, 0.04924049228429794, -0.00035854114685207605, -0.01802661642432213, 0.0006367413443513215, 0.00314054312184453, 0.018258502706885338, -0.011503562331199646, -0.02181744948029518, 0.014457589015364647, 0.014437424950301647, 0.004385670181363821, 0.008524331264197826, -0.022140072658658028, -0.005650961305946112, -0.03097190521657467, 0.035448312759399414, -0.006432316266000271, -0.050853610038757324, 0.037404220551252365, 0.011735448613762856, -0.014901196584105492, -0.018147600814700127, 0.022180400788784027, -0.022765157744288445, -0.046014249324798584, 0.009275440126657486, 0.0203656405210495, -0.026576153934001923, 0.004249563440680504, 0.017421696335077286, -0.03845274820923805, 0.00983499176800251, -0.028169110417366028, -0.0006817952962592244, -0.058193307369947433, -0.009477080777287483, 0.04302997887134552, -0.029721736907958984, 0.022986961528658867, 0.003372429171577096, 0.005484608467668295, 0.004088251385837793, -0.012592419050633907, -0.010157615877687931, 0.009381301701068878, 0.031334858387708664, -0.0018739918014034629, -0.010959134437143803, 0.050651971250772476, -0.01540529727935791, 0.002258368069306016, -0.0019181006355211139, 0.005247681401669979, -0.01748218946158886, -0.0060088722966611385, -0.028572389855980873, -0.026193037629127502, -0.0021562878973782063, -0.004138661082834005, -0.023995161056518555, -0.00739514734596014, -0.0008002587710507214, 0.0192062109708786, 0.006160102318972349, 0.027483534067869186, -0.029015997424721718, -0.018661782145500183, 0.04278801009058952, 0.0024839527904987335, 0.044360801577568054, -0.005494690500199795, 0.029721736907958984, -0.006452480331063271, 0.035750772804021835, -0.03653717041015625, 0.012874715030193329, 0.04452211409807205, -0.025709101930260658, 0.05387821048498154, 0.0388157032430172, 0.0035589460749179125, -0.005514854099601507, 0.03552896901965141, 0.005479567218571901, -0.006603710353374481, -0.036557335406541824, -0.030145181342959404, -0.037444550544023514, 0.02508401684463024, 0.00023582429275847971, 0.03407716006040573, -0.0026288817171007395, 0.024660572409629822, 0.022220728918910027, 0.023733029142022133, 0.020073262974619865, -0.01039454247802496, -0.05274902656674385, -0.011715284548699856, 0.025366313755512238, 0.023007124662399292, 0.002454967238008976, 0.0056358384899795055, 0.06682349741458893, -0.016111036762595177, 0.008070641197264194, -0.026878613978624344, 0.0038614061195403337, -0.03704126924276352, -0.022462697699666023, -0.003027120605111122, 0.009189743548631668, 0.03591208532452583, -0.008554577827453613, 0.004375588148832321, 0.03837209567427635, -0.007354819215834141, -0.011755612678825855, 0.03345207870006561, -0.008786463178694248, -0.011685038916766644, 0.029338622465729713, -0.024559753015637398, -0.02367253787815571, -0.007959739305078983, 0.005681207403540611, -0.006003831513226032, -0.050853610038757324, -0.007813550531864166, -0.0034001546446233988, 0.017220057547092438, -0.034903887659311295, -0.000540332228410989, 0.0096232695505023, -0.027302056550979614, -0.0028506857343018055, -0.012058072723448277, 0.006064323242753744, 0.011523726396262646, -0.014649147167801857, -0.040932923555374146, 0.04042882099747658, -0.02304745279252529, -0.008191625587642193, -0.02996370568871498, -0.02236187644302845, 0.020849576219916344, 0.03381503000855446, -0.025527626276016235, -0.021414170041680336, -0.01686718687415123, 0.03216158226132393, -0.04976475611329079, 0.015496035106480122, -0.008010149002075195, 0.0023037372156977654, -9.349480387754738e-05, -0.02693910524249077, 0.03369404748082161, -0.03899717703461647, 0.014457589015364647, -0.011070036329329014, 0.040549807250499725, 0.01690751500427723, 0.018802931532263756, 0.029782230034470558, -0.011352332308888435, 0.020032934844493866, -0.013681274838745594, -0.016322758048772812, -0.05855625867843628, -0.009008267894387245, -0.011533808894455433, -0.022382041439414024, -0.0097039258107543, -0.010001344606280327, -0.0014203018508851528, 0.004441121127456427, 0.031113052740693092, -0.0023428048007190228, -0.03153649717569351, -0.051579516381025314, -0.018954161554574966, -0.009698884561657906, -0.00827732216566801, 0.00902843102812767, 0.004468846600502729, 0.009013308212161064, -0.020295066758990288, -0.024136308580636978, -0.01052560843527317, 0.010233230888843536, 0.0204059686511755, -0.012652910314500332, -0.021777121350169182, -0.03012501820921898, -0.019145719707012177, 0.0038009141571819782, 0.01975063979625702, -0.0014089596224948764, 0.0011235129786655307, -0.03288748487830162, -0.03635569289326668, -0.0009779540123417974, 0.026112381368875504, 0.006548259407281876, 0.008610028773546219, 0.0447237528860569, 0.03907783329486847, 0.06307299435138702, 0.004108414985239506, 0.019871622323989868, -0.022220728918910027, -0.0024637889582663774, -0.013832504861056805, -0.0052426401525735855, 0.031213873997330666, 0.03992472216486931, 0.019528834149241447, -0.0010145013220608234, 0.018339158967137337, -0.014286194927990437, 0.0018399651162326336, 0.0041915918700397015, 0.024297621101140976, 0.004826757591217756, -0.0364968404173851, -0.04071111977100372, 0.03437962010502815, 0.025789758190512657, -0.029862886294722557, 0.025527626276016235, -0.004804073367267847, 0.022966796532273293, 0.0324237123131752, 0.005403952207416296, 0.023410405963659286, -0.0017782128416001797, -0.009189743548631668, 0.005106533411890268, -0.039319802075624466, -0.014094636775553226, -0.013580454513430595, -0.02363220974802971, 0.02005309984087944, -0.04145718738436699, 0.034480441361665726, -0.0121790561825037, -0.02232154831290245, -0.04315096139907837, -0.02609221823513508, 0.018772685900330544, 0.004378108773380518, 0.011775776743888855, -0.011301922611892223, 0.029499933123588562, -0.0006389467744156718, 0.003261527279391885, 0.028411077335476875, 0.008030313067138195, 0.026979433372616768, -0.0263140220195055, -0.0007706428878009319, 0.0010334050748497248, -0.007012031506747007, 0.032947976142168045, 0.0017265425994992256, 0.00092817418044433, -0.013651028275489807, -0.04738540202379227, 0.002691894071176648, -0.009845073334872723, -0.003937021363526583, 0.04859524220228195, 0.027644844725728035, -0.003246404230594635, -0.000845627801027149, -0.010666756890714169, -0.007480844389647245, -0.021877940744161606, -0.01039454247802496, -0.0036496841348707676, 0.011382578872144222, -0.037484876811504364, 0.007006990257650614, -0.045812610536813736, 0.012874715030193329, 0.018117355182766914, -0.013167092576622963, -0.01756284572184086, 0.017270466312766075, 0.03488372266292572, 0.03718241676688194, -0.020143836736679077, 0.008857037872076035, 0.006029036361724138, -0.01317717507481575, -0.02728189341723919, -0.043352603912353516, 0.005424116272479296, -0.003606835613027215, -0.010807904414832592, -0.010686920955777168, -0.032947976142168045, 0.006200430449098349, -0.0008702026680111885, 0.013630865141749382, 0.020335394889116287, -0.03827127441763878, -0.00891248881816864, -0.0011455672793090343, -0.003495933720842004, 0.03883586451411247, -0.004690650850534439, -0.005736658349633217, -0.005504772067070007, 0.0012155112344771624, -0.02474122866988182, 0.013409060426056385, -0.02020432986319065, 0.0013623302802443504, -0.0023743112105876207, 0.018762603402137756, 0.01759309135377407, -0.06658153235912323, 0.006018954329192638, 0.05109557881951332, 0.013318322598934174, 0.008000067435204983, 0.04637720063328743, -0.03522650897502899, 0.030104853212833405, 0.015808576717972755, -0.013630865141749382, 0.047546714544296265, -0.017220057547092438, -0.02677779272198677, 0.018339158967137337, 0.04621589183807373, -0.013207420706748962, -0.014719720929861069, -0.007556459400802851, 0.02304745279252529, -0.04714343324303627, -0.050813283771276474, 0.031556662172079086, 0.013872832991182804, -0.036133889108896255, 0.022906305268406868, 0.004607474431395531, 0.014114800840616226, 0.03187928721308708, 0.02286597713828087, -0.043392930179834366, 0.010596182197332382, -0.05194246768951416, 0.033794865012168884, -0.05024868994951248, -0.003720258129760623, 0.01867186464369297, 0.03742438554763794, 0.005333378445357084, 0.01467939279973507, -0.026152709499001503, 0.012189138680696487, -0.013167092576622963, -0.003158186562359333, 0.027362549677491188, -0.039319802075624466, -0.03895685076713562, 0.01913563720881939, 0.004584789741784334, -0.0284715685993433, -0.0021260417997837067, 0.036174219101667404, -0.008504167199134827, 0.011432988569140434, 0.01709907315671444, -0.002201656810939312, -0.0026137586683034897, 0.0151935750618577, -0.03569028154015541, -0.027100417762994766, -0.01786530576646328, 0.022563517093658447, 0.009335932321846485, 0.012662992812693119, 0.002230642596259713, -0.015485952608287334, 0.006785186473280191, 0.03661782667040825, 0.03077026642858982, 0.0004896071623079479, 0.014195457100868225, 0.012400860898196697, -0.006150020286440849, -0.01459873653948307, 0.006528095342218876, 0.025225166231393814, -0.005288009066134691, -0.0005163874593563378, 0.033673882484436035, 0.03512569144368172, 0.006376865319907665, -0.016040463000535965, 0.03750504180788994, 0.010208025574684143, -0.0007926973048597574, 0.000954009301494807, -0.011846350505948067, 0.01962965540587902, -0.014507998712360859, 0.0051468610763549805, -0.0008160119177773595, 0.016897432506084442, -0.030568625777959824, -0.018702110275626183, 0.034480441361665726, 0.07662320137023926, 0.052789356559515, -0.020688265562057495, 0.029378948733210564, -3.0482298825518228e-05, -0.03353273496031761, 0.01725030317902565, -0.036597661674022675, -0.02159564569592476, 0.0011109104380011559, -0.001511039794422686, -0.02613254450261593, 0.02248286083340645, -0.038896359503269196, 0.020869741216301918, 0.04294932261109352, -0.013640946708619595, 0.014891115017235279, 0.005414034239947796, 0.008443675003945827, -0.01245127059519291, 0.008882242254912853, 0.02655598893761635, -0.011866514571011066, 0.03597257658839226, -0.01667562872171402, -0.003969787620007992, -0.0367388091981411, 0.032141417264938354, 0.0012804140569642186, -0.004738540388643742, -0.009169579483568668, -0.0028809315990656614, 0.011997580528259277, -0.016685711219906807, 0.0222005657851696, -0.0006698229117318988, 0.004473887849599123, 0.0009420369169674814, -0.014024063013494015, -0.01652439869940281, 0.006185307167470455, -0.000982364872470498, 0.009124210104346275, 0.012804140336811543, -0.001242606551386416, 0.004574707709252834, 0.02189810574054718, -0.03772684559226036, -0.01901465281844139, 0.01241094246506691, -0.03054846078157425, -0.017391450703144073, 0.008262199349701405, 0.0037227787543088198, -0.014175293035805225, 0.009955975227057934, 0.01256217248737812, -0.0035740691237151623, -0.0004032800206914544, 0.0162925124168396, -0.002206697827205062, -0.014951607212424278, -0.019276784732937813, -0.0013862750492990017, 0.018954161554574966, -0.0121790561825037, 0.00024937198031693697, -0.0036194382701069117, -0.015576690435409546, -0.00904859509319067, 0.008902406319975853, 0.0003267198335379362, -0.015919478610157967, 0.020426133647561073, -0.00949220359325409, 0.0007681224378757179, -0.026374513283371925, -0.0037454632110893726, -0.03411749005317688, -0.009114128537476063, 0.014971770346164703, -0.009340973570942879, 0.015848904848098755, 0.010938970372080803, 0.020184164866805077, -0.033210109919309616, -0.030246000736951828, -0.016000134870409966, 0.016705874353647232, -0.015526280738413334, 0.0037404221948236227, 0.015919478610157967, 0.03611372411251068, 0.002936382545158267, -0.0020428653806447983, 0.03956177085638046, -0.0243984404951334, -0.04161849990487099, -0.03232289478182793, 0.009482121095061302, 0.02516467310488224, 0.027826322242617607, -0.006457521114498377, 0.01292512472718954, -0.006417193450033665, -0.007712730206549168, -0.009930770844221115, 0.04077161103487015, 0.008030313067138195, -0.03776717558503151, -0.0034253597259521484, -0.0037555452436208725, 0.016413496807217598, 0.011503562331199646, 0.008710848167538643, -0.01002654992043972, -0.003793352749198675, 0.033976342529058456, 0.022180400788784027, 0.030185509473085403, -0.018359322100877762, -0.013378814794123173, 0.022079581394791603, -0.025265492498874664, 0.015133082866668701, -0.01536496914923191, 0.015889232978224754, 0.005182148423045874, 0.037021104246377945, 0.07311467081308365, -0.009840032085776329, 0.005046041216701269, 0.019508671015501022, -0.013872832991182804, -0.00941154733300209, -0.022886142134666443, -0.0020693305414170027, 0.011594300158321857, -0.0028658085502684116, 0.017734238877892494, 0.013368732295930386, 0.02258368209004402, 0.01571783795952797, 0.036940451711416245, -0.017320876941084862, -0.007400188595056534, -0.023027289658784866, -0.019276784732937813, -0.0010012686252593994, -0.019347358494997025, -0.00850920844823122, -0.04730474576354027, 0.015052426606416702, -0.031032398343086243, -0.004819196183234453, -0.03310928866267204, -0.018964242190122604, -0.02923780120909214, -0.011009544134140015, -0.01644374243915081, -0.005474526435136795, 0.029136981815099716, -0.003473249264061451, -0.03089124895632267, 0.006104651372879744, -6.797473906772211e-05, -0.024458933621644974, -0.024801721796393394, -0.016897432506084442, -0.012904960662126541, -0.005141820292919874, -0.03692028671503067, 0.024640409275889397, 0.0036723685916513205, -0.012037908658385277, 0.002911177696660161, 0.014346687123179436, -0.009482121095061302, 0.008156338706612587, 0.008302527479827404, -0.011543890461325645, 0.007863960228860378, -0.014266030862927437, 0.00941154733300209, -0.004118497017771006, -0.013479635119438171, -0.017502352595329285, -0.01425594836473465, 0.016736119985580444, 0.01294528879225254, -0.006714612245559692, -0.0002726866223383695, 0.012310123071074486, -0.031677644699811935, 0.004955303389579058, 0.0014782733051106334, 0.01725030317902565, -0.01077765878289938, -0.018066944554448128, -0.01890375092625618, 0.015294394455850124, -0.007662320509552956, 0.009396424517035484, 0.05682215467095375, -0.006961621344089508, 0.008307568728923798, 0.0122597124427557, 0.012441189028322697, 0.006951539311558008, -0.032867319881916046, 0.036597661674022675, -0.0013131805462762713, 0.025567952543497086, 0.01663530059158802, 0.01828874833881855, 0.004453723784536123, -0.013792176730930805, -0.010465116240084171, -0.015324641019105911, -0.039823900908231735, 0.005111574195325375, -0.03183895722031593, 0.03119370900094509, -0.00423444015905261, 0.01498185284435749, 0.04851458594202995, -0.0019609490409493446, -0.004088251385837793, 0.0009748034062795341, -0.0243581123650074, 0.02078908495604992, 0.0017504873685538769, -0.013056190684437752, -0.0002821384696289897, -0.0075766234658658504, -0.02274499274790287, 0.03488372266292572, -0.022422369569540024, -0.0054190754890441895, -8.183749014278874e-05, -0.008226912468671799, -0.007556459400802851, -0.016040463000535965, 0.010676838457584381, 0.011130528524518013, -0.049845412373542786, 0.007561500184237957, -5.222161053097807e-05, -0.04722408950328827, -0.016342923045158386, -0.015516199171543121, 0.028794193640351295, 0.015284312888979912, 0.021232692524790764, -0.022220728918910027, 0.01294528879225254, 0.013822422362864017, -0.0059836674481630325, 0.010475198738276958, -0.0027473452500998974, 0.024600081145763397, -0.017603173851966858, 0.007490926422178745, 0.0033522651065140963, 0.007642156444489956, 0.016050545498728752, 0.013257830403745174, 0.01052560843527317, 0.002065549837425351, -0.0029716696590185165, 0.031677644699811935, -0.01843997836112976, -0.009159497916698456, 0.0284715685993433, 0.03762602433562279, 0.00720358919352293, 0.020577363669872284, 0.02324909344315529, -0.01262266468256712, -0.016413496807217598, 0.0059130932204425335, -0.0042420015670359135, 0.009905565530061722, 0.04395752400159836, 0.018500471487641335, 0.028653046116232872, -0.021998925134539604, 0.0035589460749179125, 0.03393601253628731, -0.004657884128391743, -0.023712866008281708, 0.01317717507481575, 0.058999866247177124, 0.010298763401806355, -0.03835193067789078, 0.014649147167801857, -0.008413429372012615, -0.026213200762867928, -0.035206347703933716, 0.030830757692456245, -0.008594905026257038, 0.014155128970742226, -0.0062609221786260605, 0.00251167849637568, 0.005134258884936571, 0.019317112863063812, -0.013721602968871593, -0.0045898305252194405, -0.023692701011896133, -0.002946464577689767, 0.031052561476826668, 0.02728189341723919, 0.01717972941696644, -0.013711520470678806, 0.00666420254856348, 0.055813953280448914, 0.014155128970742226, 0.028209436684846878, -0.03611372411251068, -0.011221266351640224, -0.016685711219906807, -0.01809719018638134, 0.03189944848418236, 0.023410405963659286, 0.0013673712965101004, 0.025003360584378242, 0.0012886057374998927, 0.030568625777959824, -0.024882378056645393, -0.016040463000535965, -0.0046856096014380455, -0.009870278649032116, -0.009003226645290852, 0.000951488793361932, 0.021736793220043182, -0.0021285624243319035, 0.04952278733253479, -0.02889501303434372, -0.0006209881976246834, 0.020577363669872284, -0.03161715343594551, -0.00720358919352293, 0.04516736418008804, 0.00906875915825367, -0.007248958572745323, -0.005535018164664507, -0.0037757093086838722, -0.010656674392521381, -0.013751848600804806, 0.04960344359278679, -0.022503025829792023, -0.003934500738978386, 0.021756956353783607, -0.003821078222244978, -0.005373706109821796, -0.0192465391010046, 0.005877806339412928, 0.006160102318972349, -0.012673074379563332, -0.01882309466600418, 0.038049470633268356, 0.03968275338411331, 0.0018815533258020878, -0.008594905026257038, -0.013116682879626751, -0.03478290140628815, 0.00516702514141798, 0.031677644699811935, -0.029419276863336563, -0.013832504861056805, 0.04071111977100372, -0.04928081855177879, -0.03208092600107193, -0.003826119238510728, 0.02881435677409172, 0.007143097463995218, 0.014528162777423859, 0.016998253762722015, -0.0202849842607975, -0.01913563720881939, 0.018339158967137337, -0.00762703362852335, -0.010434870608150959, 0.02796746976673603, 0.009930770844221115, -0.01947842538356781, 0.0004729088395833969, -0.020809249952435493, -0.01071716658771038, -0.003354785731062293, 0.01483062282204628, -0.01017777994275093, -0.01258233655244112, 0.0038714881520718336, -0.004536900203675032, 0.001353508559986949, 0.008287404663860798, -0.017078908160328865, -0.007848837412893772, 0.045248016715049744, 0.007158220279961824, 0.011211184784770012, -0.006891047582030296, -0.013509880751371384, 0.022886142134666443, 0.0018071986269205809, 0.00537874735891819, 0.041174888610839844, 0.02286597713828087, 0.013167092576622963, -0.022543353959918022, -0.031153380870819092, 0.014013980515301228, -0.008806627243757248, 0.0303871501237154, -0.008993144147098064, 0.014860868453979492, -0.031677644699811935, -0.02197876200079918, 0.02770533785223961, -0.013620782643556595, 0.007359860464930534, 0.002142425160855055, 0.01990186981856823, -0.0020844535902142525, -0.004171427804976702, 0.005267845466732979, -0.008242035284638405, -0.033371422439813614, 0.045046377927064896, -0.04157816991209984, -0.004196632653474808, 0.00538882939144969, 0.005771945230662823, 0.023107945919036865, -0.03984406590461731, 0.027080252766609192, -0.006780145224183798, 0.0222812220454216, 0.0017630897928029299, 0.03185912221670151, 0.011614464223384857, -0.0022621487732976675, 0.03161715343594551, -0.0012432367075234652, 0.016030380502343178, 0.01798628829419613, 0.023813685402274132, 0.015647264197468758, -0.02062777243554592, 0.047667697072029114, 0.018379487097263336, 0.006780145224183798, 0.010626428760588169, -0.020375723019242287, 0.008816709741950035, 0.09856163710355759, -0.014346687123179436, -0.026374513283371925, 0.01256217248737812, 0.015203656628727913, 0.02992337755858898, 0.025648608803749084, -0.006916252430528402, -0.04153784364461899, -0.021494824439287186, 0.015485952608287334, 0.006961621344089508, -6.63600440020673e-05, 0.05698346719145775, -0.016816776245832443, 0.007889165543019772, -0.01614128239452839, 0.007788345217704773, 0.01302594505250454, -0.034137655049562454, 0.015576690435409546, 0.005625756457448006, -0.04075144603848457, -0.006628915201872587, -0.02431778609752655, 0.010278599336743355, 0.006694448180496693, 0.0034253597259521484, 0.019740557298064232, -0.0001554833579575643, -0.015959806740283966, 0.03776717558503151, -0.014528162777423859, -0.008635233156383038, -0.028653046116232872, 0.015596854500472546, 0.03081059455871582, 0.017492270097136497, -0.0222005657851696, -0.002724660560488701, -0.026576153934001923, 0.002838083077222109, -0.021494824439287186, 0.017613254487514496, 0.005429157055914402, 0.007430434226989746, -0.004410875029861927, -0.01599005237221718, -0.023107945919036865, -0.014286194927990437, 0.002787673147395253, -0.002580992178991437, 0.026616482064127922, 0.008448716253042221, 0.01671595685184002, -0.01828874833881855, 0.005711453501135111, 0.03187928721308708, -0.003362347139045596, 0.024418605491518974, -0.019498588517308235, -0.002186533762142062, -0.0052174353040754795, 0.0038840908091515303, 0.013560290448367596]\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 角度2： 硬编码",
   "id": "4b3e00739a4d5efb"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-17T14:12:04.828752Z",
     "start_time": "2025-10-17T14:12:01.041274Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "\n",
    "# 硬编码 API Key 和模型参数\n",
    "llm = ChatOpenAI(\n",
    "    api_key=\"sk-xxx\",  # 明文暴露密钥\n",
    "    base_url=\"https://api.openai-proxy.org/v1\",\n",
    "    model=\"gpt-3.5-turbo\",\n",
    ")\n",
    "\n",
    "# 调用示例\n",
    "response = llm.invoke(\"解释神经网络原理\")\n",
    "print(response.content)"
   ],
   "id": "85253c28b3944ff1",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "神经网络是一种人工智能模型，模仿人类神经系统的结构和功能来进行学习和推断。神经网络由许多神经元（或节点）组成，这些神经元之间通过连接来传递信息。\n",
      "\n",
      "在神经网络中，输入数据被输入到输入层，然后通过多个中间层逐步传递信息，最终输出到输出层。每个神经元都会对输入数据进行加权处理，并通过激活函数来产生输出结果。神经网络通过调整连接权重和偏差来学习输入和输出之间的复杂关系。\n",
      "\n",
      "训练神经网络的过程就是通过反向传播算法来调整连接权重，使得神经网络的输出与真实输出之间的误差最小化。这种训练过程需要大量的数据来进行，以确保神经网络能够泛化到未见过的数据。\n",
      "\n",
      "总的来说，神经网络利用神经元之间的连接和权重来模拟人脑的学习和推断过程，从而实现对复杂问题的解决和预测。\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 角度2：使用.env配置文件",
   "id": "c7fbd8509d28fcc7"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-17T14:20:14.668260Z",
     "start_time": "2025-10-17T14:20:10.662743Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from dotenv import load_dotenv\n",
    "from langchain_openai import ChatOpenAI\n",
    "import os\n",
    "\n",
    "load_dotenv()  # 自动加载 .env 文件\n",
    "llm = ChatOpenAI(\n",
    "    api_key=os.getenv(\"OPENAI_API_KEY\"),  # 安全读取\n",
    "    base_url=os.getenv(\"OPENAI_BASE_URL\"),\n",
    "    model=\"gpt-4o-mini\",\n",
    "    temperature=0.7,\n",
    ")\n",
    "response = llm.invoke(\"RAG 技术的核心流程\")\n",
    "print(response.content)"
   ],
   "id": "3b72b543687392c5",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "RAG（Retrieval-Augmented Generation）技术的核心流程主要包括以下几个步骤：\n",
      "\n",
      "1. **查询生成**：首先，根据用户的输入或问题生成一个查询。这通常涉及自然语言处理技术，以确保生成的查询能够有效地检索相关信息。\n",
      "\n",
      "2. **信息检索**：使用生成的查询从外部知识库或文档集合中检索相关信息。这一步通常依赖于搜索引擎、数据库或特定的知识图谱，旨在找到与查询最相关的文档或段落。\n",
      "\n",
      "3. **结果过滤与排序**：对检索到的信息进行过滤和排序，以确保最终选择的内容是最相关和最有用的。这可能涉及一些评分机制，帮助确定哪些文档最符合用户的需求。\n",
      "\n",
      "4. **生成回答**：将选定的相关信息与用户的原始查询结合，生成最终的回答。这一步通常使用生成模型（如GPT等）来生成自然语言的响应。\n",
      "\n",
      "5. **输出**：将生成的回答返回给用户，通常还会附带一些来源信息或相关的上下文，以提高回答的可信度和可追溯性。\n",
      "\n",
      "整个RAG流程的关键在于结合检索和生成的优点，既能够利用大量外部知识，提高回答的准确性，也能够生成自然流畅的语言响应。\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "## 角度2：给os内部的环境变量赋值",
   "id": "1fb4c7e9f2b8aabd"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-17T14:23:20.136948Z",
     "start_time": "2025-10-17T14:23:17.224893Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_openai import ChatOpenAI\n",
    "import dotenv\n",
    "\n",
    "dotenv.load_dotenv()\n",
    "import os\n",
    "\n",
    "os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\")\n",
    "os.environ[\"OPENAI_API_BASE\"] = os.getenv(\"OPENAI_BASE_URL\")\n",
    "text = \"猫王是猫吗？\"\n",
    "CHAT_MODEL = ChatOpenAI(\n",
    "    model=\"gpt-4o-mini\",\n",
    "    temperature=0.7,\n",
    "    max_tokens=300,\n",
    ")\n",
    "response = CHAT_MODEL.invoke(text)\n",
    "print(type(response))\n",
    "print(response.content)"
   ],
   "id": "cd4f023084bac98f",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'langchain_core.messages.ai.AIMessage'>\n",
      "“猫王”通常指的是美国著名的摇滚歌手埃尔维斯·普雷斯利（Elvis Presley），因为他的英文名字“King of Rock and Roll”有时被戏称为“猫王”。所以“猫王”并不是指真正的猫，而是一个人名的别称。如果你是在询问某个特定的“猫王”角色或文化现象，请提供更多信息。\n"
     ]
    }
   ],
   "execution_count": 6
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
